﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EasyToHelp.Business;
using EasyToHelp.Service;
using Microsoft.AspNetCore.Mvc;

namespace EasyToHelp.WEBSystem.Controllers
{
    public class MenusManageController : Controller
    {
        private readonly ISysMenusService sysMenus;
        public MenusManageController(ISysMenusService _sysMenus)
        {
            sysMenus = _sysMenus;
        }
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult GetChildrenSysMenus(int Id, string ThisName)
        {
            var ylist = sysMenus.GetChildrenSysMenusList(Id);
            StringBuilder sb = new StringBuilder();
            if (ylist.Count > 0)
            {
                ylist.ForEach(y =>
                {
                    sb.Append(" <li class=\"layui-nav-item layui-nav-itemed\">\r\n");
                    sb.Append("     <a href = \"javascript:; \" > " + ThisName + " </ a >\r\n");
                    sb.Append("     <dl class=\"layui -nav-child\">\r\n");
                    var zlist = sysMenus.GetChildrenSysMenusList(y.Id);
                    if (zlist.Count > 0)
                    {
                        sb.Append("         <dd>\r\n");
                        sb.Append("             < a href=\"javascript:; \">" + y.text + "</a>");
                        sb.Append("             <dl class=\"layui -nav-child\">\r\n");
                        zlist.ForEach(z =>
                        {
                            sb.Append("             <dd><a href = \"" + z.href + "\" > " + z.text + " </ a ></ dd >\r\n");
                        });
                        sb.Append("             </dl >\r\n");
                        sb.Append("         </ dd >\r\n");
                    }
                    else
                    {
                        sb.Append("             <dd><a href = \"" + y.href + "\" > " + y.text + " </ a ></ dd >\r\n");
                    }
                    sb.Append("         <dd ></dd>\r\n");

                    sb.Append("     </dl >\r\n");
                    sb.Append(" </li>\r\n");
                });
            }
            return Content(sb.ToString());
        }
    }
}